#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
int a[200010];
void solve()
{
	int n;
	cin>>n;
	int a1=1e9+10;
	for(int i=1;i<=n;i++) 
	{
		cin>>a[i];
		a1=min(a1,a[i]);
	}
	int cnt=0;
	int f=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==a1)
		{
			cnt=i-1;
			int j=i+1;
			while(j<=n)
			{
				if(a[j]<a[j-1])
				{
					f=0;
					break;
				}
				j++;
			}
			break;
		}
	}
	if(f) cout<<cnt<<endl;
	else cout<<-1<<endl;
}
int main()
{
	IOS;
	int T=1;
	cin>>T;

	while(T--)
	{
		solve();
	}

	return 0;
}

